/* 
 * Hawk - A Component Based Test Framework
 *
 * Copyright (C) 2010 http://code.google.com/p/hawk-framework/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package org.hawk.applications.finder.android.gui;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

/**
 * Profile activity tab. This tab allows the user indicates their preferences
 * 
 * @author Rodrigo Prestes Machado
 */
public class ProfileActivity extends Activity {

	private Spinner spinnerHardware;
	private Spinner spinnerNetwork;
	private Spinner spinnerTest;
	private Spinner spinnerModel;
	private Spinner spinnerProject;
	private EditText formName;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profile);
		init();
		
		Button buttonSave = (Button) findViewById(R.id.buttonSave);
		buttonSave.setOnClickListener(new SaveProfileEvent());
		
		formName = (EditText) findViewById(R.id.edittext);
		
	}

	/**
	 * Starts the user interface for this tab
	 */
	private void init() {
		
		ArrayAdapter<CharSequence> adapter;

		// Fills the spinners components
		spinnerHardware = (Spinner) findViewById(R.id.spinner_hardware);
		adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerHardware.setAdapter(adapter);
		
		spinnerNetwork = (Spinner) findViewById(R.id.spinner_network);
		adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerNetwork.setAdapter(adapter);
		
		spinnerTest = (Spinner) findViewById(R.id.spinner_test);
		adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerTest.setAdapter(adapter);	
		
		spinnerModel = (Spinner) findViewById(R.id.spinner_model);
		adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerModel.setAdapter(adapter);
		
		spinnerProject = (Spinner) findViewById(R.id.spinner_project);
		adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerProject.setAdapter(adapter);
		
	}
	
	/**
	 * Save the user profile and preferences
	 */
	public class SaveProfileEvent implements OnClickListener {
		public void onClick(View v) {
			
			String value = (String) spinnerHardware.getSelectedItem();
			
			Editable valueName = formName.getText();
			
			Toast.makeText(ProfileActivity.this, valueName.toString(),
					Toast.LENGTH_SHORT).show();
		}
	}
	
}